<template>
  <el-config-provider :locale="currentLocale">
    <!-- <el-watermark :font="font" :content="title">
      <router-view />
    </el-watermark> -->
    <router-view />
    <ReDialog />
  </el-config-provider>
</template>

<script setup lang="ts">
import { ReDialog } from "@/components/ReDialog";
import { ElConfigProvider } from "element-plus";
import en from "element-plus/es/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import { computed, reactive } from "vue";
import { getConfig } from "./config";
import { useToolsStore } from "@/store/modules/tools";
import { reportApi } from "@/api/report-api";
import { useNav } from "@/layout/hooks/useNav";

// 水印字体设置
const font = reactive({
  color: "rgba(0, 0, 0, .15)"
});

// 获取配置的标题
const title = getConfig().Title;

const toolsStore = useToolsStore();
const { $storage } = useNav();

// 获取字典数据
async function queryDictionaryData() {
  if (location.pathname.includes("login")) {
    return;
  }
  try {
    const response = await reportApi.queryReportDict();
    if (response?.data) {
      toolsStore.setDictData(response.data);
      console.log("获取到的字典数据:", response.data);
    }
  } catch (err) {
    console.error("获取字典数据失败:", err);
  }
}
queryDictionaryData();

// 计算当前语言
const currentLocale = computed(() => {
  return ($storage.locale?.locale ?? "zh") === "zh" ? zhCn : en;
});

// 组件注册
const components = {
  [ElConfigProvider.name]: ElConfigProvider,
  ReDialog
};
</script>
